package main

import "fmt"

// 返回单个返回值，匿名
func f1(a int, b int) int {
	fmt.Println("=====f1=====")
	fmt.Println("a = ",a,", b = ",b)
	
	//c := 10

	return 10
}

// 返回多个返回值,无形参名称
func f2(a int,b string) (int, string) {
	fmt.Println("====f2====")
	fmt.Println("a = ",a,",b = ",b)
	
	return 100, "abc"
}

// 返回多个返回值，有形参名称
func f3(a int,b bool) (r1 int, r2 bool) {
	fmt.Println("====f3====")
	fmt.Println("a = ",a,",b = ",b)
	
	// 给有名称的返回值赋值 不赋值默认0 false
	r1 = 100
	r2 = true
	return
}

// 返回多个返回值，类型相同
func f4(a int, b string) (r1,r2 int) {
	fmt.Println("====f4====")
	fmt.Println("a = ",a,",b = ",b)
	return r1,r2
}

func main(){
	f1 := f1(1,2)
	fmt.Println("f1 = ",f1)

	ret1, ret2 := f2(3,"abc")
	fmt.Println("ret1 = ",ret1,",ret2 = ",ret2);

	ret3, ret4 := f3(100,false)
	fmt.Println("ret3 = ",ret3,",ret4 = ",ret4)
	
	//前面已定义的变量，重新赋值，需要类型一致 
	// 报错：cannot assign int to ret4 (type bool) in multiple assignment
	//ret3,ret4 = f4(101,"aaa")

	ret5,ret6 := f4(101,"bbb")
	fmt.Println("ret5 = ",ret5,",ret6 = ",ret6)
}
